package validation.jexp;

import com.jgoodies.binding.adapter.BasicComponentFactory;
import com.jgoodies.binding.value.ConverterFactory;
import com.jgoodies.binding.value.ValueHolder;
import com.jgoodies.binding.value.ValueModel;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;

import javax.swing.*;

/**
 * JGoodies Binding: Converter Factory Example
 */
public class ConverterFactoryExample extends JPanel {

    public ConverterFactoryExample() {
        DefaultFormBuilder defaultFormBuilder = new DefaultFormBuilder(new FormLayout("p, 2dlu, p:g"));
        defaultFormBuilder.setDefaultDialogBorder();
        ValueModel booleanModel = new ValueHolder(true);
        ValueModel negativeBooleanModel = ConverterFactory.createBooleanNegator(booleanModel);
        ValueModel stringModel = ConverterFactory.createBooleanToStringConverter(booleanModel, "Is True", "Is Not True");
        defaultFormBuilder.append("CheckBox1:", BasicComponentFactory.createCheckBox(booleanModel, "True is Checked"));
        defaultFormBuilder.append("CheckBox2:", BasicComponentFactory.createCheckBox(negativeBooleanModel, "True is Not Checked"));
        defaultFormBuilder.append("Text Field: ", BasicComponentFactory.createTextField(stringModel));
        add(defaultFormBuilder.getPanel());
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JGoodiesValidationUtils.showFrame("Converter Factory Example", new ConverterFactoryExample());
        });
    }
}
